package com.guigu.health.service.impl;

import com.guigu.health.dao.OrderMapper;
import com.guigu.health.dao.OrderSettingMapper;
import com.guigu.health.pojo.Order;
import com.guigu.health.pojo.OrderSetting;
import com.guigu.health.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:OrderSettingServiceImpl
 * @Description:预约设置业务实现类
 * @Author:longtao
 * @Date:2021/4/12
 * @Version:1.0
 */
@Service("orderSettingService")
public class OrderSettingServiceImpl implements OrderSettingService {
    private OrderSettingMapper orderSettingMapper;
    @Autowired
    @Qualifier(value = "orderSettingMapper")
    public void setOrderMapper(OrderSettingMapper orderSettingMapper) {
        this.orderSettingMapper = orderSettingMapper;
    }

    /**
     * 设置每天的预约人数
     * @param order
     * @return
     */
    @Override
    public boolean addOrderSetting(OrderSetting order) {
        boolean b=false;
        int i = orderSettingMapper.insert(order);
        if (i>0){
            b=true;
        }
        return b;
    }

    @Override
    public List<OrderSetting> queryAllOrderSetting() {
        List<OrderSetting> list = orderSettingMapper.selectByExample(null);
        return list;
    }

    @Override
    public List<Map> getOrderSettingByMonth(String date) {
        // 1.组织查询Map，dateBegin表示月份开始时间，dateEnd月份结束时间
        String dateBegin = date + "-1";//2019-03-1
        String dateEnd = date + "-31";//2019-03-31
        Map map = new HashMap();
        map.put("dateBegin",dateBegin);
        map.put("dateEnd",dateEnd);
        // 2.查询当前月份的预约设置
        List<OrderSetting> list = orderSettingMapper.getOrderSettingByMonth(map);
        List<Map> data = new ArrayList<>();
        // 3.将List<OrderSetting>，组织成List<Map>
        for (OrderSetting orderSetting : list) {
            Map orderSettingMap = new HashMap();
            /**
             * 获得日期（几号）
             */
            orderSettingMap.put("date",orderSetting.getOrderDate().getDate());
            /**
             * 可预约人数
             */
            orderSettingMap.put("number",orderSetting.getNumber());
            /**
             * 已预约人数
             */
            orderSettingMap.put("reservations",orderSetting.getReservations());
            data.add(orderSettingMap);
        }
        return data;
    }
}
